#pragma once
#include<iostream>
#include"RBTree.h"
namespace bit
{
	template<class K,class T>
	struct MapKeyOfT
	{
		template<class K, class T>
		const K& operator()(const std::pair<K,T>& x)
		{
			return x.first;
		}
	};
	template< class K,class T>
	class map
	{
	
	public:
		typedef typename const K key_type;
		typedef typename std::pair<const K, T> value_type;
	    typedef typename RBTree< std::pair<const K,T>, MapKeyOfT<const K,T>> Tree;
		typedef RBTreeNode<value_type> Node;
		typedef typename  bit::_TreeIterator<value_type, value_type&, value_type*>::iterator iterator;
		typedef typename bit::_TreeIterator<value_type,value_type&,value_type*>::const_iterator const_iterator;
	public:
		Tree* _tree;
		map()
		{
			_tree = new Tree();
		}

		iterator begin()
		{
			 iterator* ret=new iterator( _tree->left_most());
			 return *ret;
		}
		const_iterator begin()const
		{
			return _tree->begin();
		}
		iterator end()
		{
			iterator* ret = new iterator();
			return *ret;
		}
		const_iterator end()const
		{
			const_iterator* ret = new const_iterator();
			return *ret;
		}
		iterator insert(const value_type& value)
		{
			return _tree->insert(value);
		}

	    T& operator[](key_type key)
		{
			return  (insert(std::make_pair(key, T())))->second;
		}


	};
}
